// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   change_ok.java

package ecommerce.website.link;

import com.jspsmart.upload.*;
import include.get_sql.getInsertSql;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class change_ok extends HttpServlet
{

	public change_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		try
		{
			HttpSession dbSession = request.getSession();
			JspFactory _jspxFactory = JspFactory.getDefaultFactory();
			javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
			ServletContext dbApplication = dbSession.getServletContext();
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			nseer_db_backup1 ecommerce_db = new nseer_db_backup1(dbApplication);
			ValidataNumber validata = new ValidataNumber();
			ValidataTag vt = new ValidataTag();
			counter count = new counter(dbApplication);
			getInsertSql getInsertSql = new getInsertSql();
			getAttachmentLength getAttachmentLength = new getAttachmentLength();
			getAttachmentType getAttachmentType = new getAttachmentType();
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			if (ecommerce_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				String file_type = "jpg,gif,bmp";
				long d = getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				String link_ID = request.getParameter("link_ID");
				try
				{
					mySmartUpload.upload();
					String topic = mySmartUpload.getRequest().getParameter("topic");
					String url = mySmartUpload.getRequest().getParameter("url");
					String content = new String(mySmartUpload.getRequest().getParameter("content").getBytes("UTF-8"), "UTF-8");
					String changer_ID = mySmartUpload.getRequest().getParameter("changer_ID");
					String changer = mySmartUpload.getRequest().getParameter("changer");
					String change_time = mySmartUpload.getRequest().getParameter("change_time");
					String file_name[] = new String[mySmartUpload.getFiles().getCount()];
					String not_change[] = new String[mySmartUpload.getFiles().getCount()];
					String lately_change_time = mySmartUpload.getRequest().getParameter("lately_change_time");
					String file_change_amount = mySmartUpload.getRequest().getParameter("file_change_amount");
					int change_amount = Integer.parseInt(file_change_amount) + 1;
					if (vt.validata((String)session.getAttribute("unit_db_name"), "ecommerce_link", "link_ID", link_ID, "check_tag").equals("1"))
					{
						String sqloo = (new StringBuilder("select * from ecommerce_link where link_ID='")).append(link_ID).append("'").toString();
						ResultSet rsoo = ecommerce_db.executeQuery(sqloo);
						if (rsoo.next())
						{
							String sqll = (new StringBuilder("insert into ecommerce_link_dig(link_ID,topic,url,content,attachment1,attachment2,attachment3,opinion,CHECK_TAG,FILE_CHANGE_AMOUNT,REGISTER,CHECKER,CHANGER,REGISTER_ID,CHECKER_ID,CHANGER_ID,REGISTER_TIME,CHECK_TIME,CHANGE_TIME,LATELY_CHANGE_TIME,EXCEL_TAG) values('")).append(rsoo.getString("link_ID")).append("','").append(rsoo.getString("topic")).append("','").append(rsoo.getString("url")).append("','").append(rsoo.getString("content")).append("','").append(rsoo.getString("attachment1")).append("','").append(rsoo.getString("attachment2")).append("','").append(rsoo.getString("attachment3")).append("','").append(rsoo.getString("opinion")).append("','").append(rsoo.getString("CHECK_TAG")).append("','").append(rsoo.getString("FILE_CHANGE_AMOUNT")).append("','").append(rsoo.getString("REGISTER")).append("','").append(rsoo.getString("CHECKER")).append("','").append(rsoo.getString("CHANGER")).append("','").append(rsoo.getString("REGISTER_ID")).append("','").append(rsoo.getString("CHECKER_ID")).append("','").append(rsoo.getString("CHANGER_ID")).append("','").append(rsoo.getString("REGISTER_TIME")).append("','").append(rsoo.getString("CHECK_TIME")).append("','").append(rsoo.getString("CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_CHANGE_TIME")).append("','").append(rsoo.getString("EXCEL_TAG")).append("')").toString();
							ecommerce_db.executeUpdate(sqll);
						}
						String sql1 = (new StringBuilder("select * from ecommerce_link where link_ID='")).append(link_ID).append("'").toString();
						ResultSet rs = ecommerce_db.executeQuery(sql1);
						rs.next();
						String attachment[] = mySmartUpload.getRequest().getParameterValues("attachment");
						String delete_file_name[] = new String[0];
						if (attachment != null)
						{
							delete_file_name = new String[attachment.length];
							for (int i = 0; i < attachment.length; i++)
								delete_file_name[i] = rs.getString(attachment[i]);

						}
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							SmartFile file = mySmartUpload.getFiles().getFile(i);
							if (file.isMissing())
							{
								file_name[i] = "";
								int q = i + 1;
								String field_name = (new StringBuilder("attachment")).append(q).toString();
								if (!rs.getString(field_name).equals(""))
									not_change[i] = "yes";
							} else
							{
								int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "ecommerceAttachmentcount");
								count.write((String)dbSession.getAttribute("unit_db_name"), "ecommerceAttachmentcount", filenum);
								file_name[i] = (new StringBuilder(String.valueOf(filenum))).append(file.getFileName()).toString();
								file.saveAs((new StringBuilder(String.valueOf(path))).append("ecommerce/file_attachments/").append(filenum).append(file.getFileName()).toString());
							}
						}

						String sqla = (new StringBuilder("update ecommerce_link set topic='")).append(topic).append("',url='").append(url).append("',content='").append(content).append("',check_tag='0',excel_tag='0',changer_ID='").append(changer_ID).append("',changer='").append(changer).append("',change_time='").append(change_time).append("',lately_change_time='").append(lately_change_time).append("',file_change_amount='").append(change_amount).append("'").toString();
						String sqlb = (new StringBuilder(" where link_ID='")).append(link_ID).append("'").toString();
						if (attachment != null)
						{
							for (int i = 0; i < attachment.length; i++)
							{
								sqla = (new StringBuilder(String.valueOf(sqla))).append(",").append(attachment[i]).append("=''").toString();
								File file = new File((new StringBuilder(String.valueOf(path))).append("ecommerce/file_attachments/").append(delete_file_name[i]).toString());
								file.delete();
							}

						}
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
							if (not_change[i] == null || !not_change[i].equals("yes"))
							{
								int p = i + 1;
								sqla = (new StringBuilder(String.valueOf(sqla))).append(",attachment").append(p).append("='").append(file_name[i]).append("'").toString();
							}

						String sql = (new StringBuilder(String.valueOf(sqla))).append(sqlb).toString();
						ecommerce_db.executeUpdate(sql);
						List rsList = GetWorkflow.getList(ecommerce_db, "ecommerce_config_workflow", "10");
						String elem[] = new String[3];
						if (rsList.size() == 0)
						{
							sql = (new StringBuilder("update ecommerce_link set check_tag='1' where link_ID='")).append(link_ID).append("'").toString();
							ecommerce_db.executeUpdate(sql);
						} else
						{
							sql = (new StringBuilder("delete from ecommerce_workflow where object_ID='")).append(link_ID).append("'").toString();
							ecommerce_db.executeUpdate(sql);
							sql = (new StringBuilder("update ecommerce_link set check_tag='0' where link_ID='")).append(link_ID).append("'").toString();
							ecommerce_db.executeUpdate(sql);
							for (Iterator ite = rsList.iterator(); ite.hasNext(); ecommerce_db.executeUpdate(sql))
							{
								elem = (String[])ite.next();
								sql = (new StringBuilder("insert into ecommerce_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(link_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
							}

						}
						response.sendRedirect("ecommerce/website/link/change_ok_a.jsp");
					} else
					{
						response.sendRedirect("ecommerce/website/link/change_ok_c.jsp");
					}
					ecommerce_db.commit();
					ecommerce_db.close();
				}
				catch (Exception ex)
				{
					response.sendRedirect((new StringBuilder("ecommerce/website/link/change_ok_b.jsp?link_ID=")).append(link_ID).toString());
				}
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
